package personal.wang.handler;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import personal.wang.message.Header;
import personal.wang.message.Message;
import personal.wang.enm.MessageType;
import personal.wang.util.MessageUtil;

/**
 * @className: WorkerHandler
 * @Description:
 * @Author: wangyifei
 * @Date: 2025/2/14 16:02
 */
public class WorkerHandler extends ChannelInboundHandlerAdapter {
    private static Logger logger = LoggerFactory.getLogger(WorkerHandler.class);

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        Message m = (Message) msg;
        Header header = m.getHeader();
        MessageType messageType = MessageUtil.int2MessageType(header.getFlag());
        messageType.getHandler().handler(m , ctx);
        super.channelRead(ctx, msg);
    }
}
